package com.ruoyi.yljf.service.impl;

import java.util.Collections;
import java.util.List;

import com.ruoyi.yljf.domain.dto.TableVO;
import com.ruoyi.yljf.mapper.TableMapper;
import com.ruoyi.yljf.service.TableService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.yljf.domain.Table;
import com.ruoyi.yljf.service.TableService;

import javax.annotation.Resource;

/**
 * 标签管理Service业务层处理
 * 
 * @author TAT
 * @date 2025-03-10
 */
@Service
public class TableServiceImpl extends ServiceImpl<TableMapper, Table> implements TableService {
    @Resource
    private TableMapper TableMapper;
    
    /**
     * 查询标签管理列表
     * 
     * @param table 标签管理
     * @return 标签管理
     */
    @Override
    public List<Table> selectTableList(Table table) {
    	LambdaQueryWrapper<Table> queryWrapper = Wrappers.lambdaQuery();
        if (StringUtils.isNotEmpty(table.getTableName())) {
			queryWrapper.like(Table::getTableName, table.getTableName());
		}
        if (StringUtils.isNotNull(table.getUseNum())) {
			queryWrapper.eq(Table::getUseNum, table.getUseNum());
		}
        return TableMapper.selectList(queryWrapper);
    }

    @Override
    public List<Table> queryTableList(TableVO vo) {
        LambdaQueryWrapper<Table> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.select(Table::getId,  Table::getTableName, Table::getUseNum); // 明确指定返回的字段
        if (StringUtils.isNotEmpty(vo.getKeyWord())) {
            queryWrapper.like(Table::getTableName, vo.getKeyWord());
        }
        queryWrapper.orderByDesc(Table::getUseNum).last("limit 5");
        return TableMapper.selectList(queryWrapper);
    }


}
